﻿using InstallationClient.Hubs;
using Microsoft.AspNetCore.SignalR;

namespace InstallationClient.Mqtt {
    /// <summary>
    /// 
    /// </summary>
    public class MqttHostedService : IHostedService, IDisposable {
        private MqttServerHelper _helper;
        private readonly IHubContext<LogHub> _hubContext;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="helper"></param>
        public MqttHostedService(MqttServerHelper helper, IHubContext<LogHub> hubContext) {
            _helper = helper;
            _hubContext = hubContext;
        }
        /// <summary>
        /// 启动服务
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task StartAsync(CancellationToken cancellationToken) {
            await _helper.RunMqttServer();
            //await _hubContext.Clients.All.SendAsync("ReceiveData", $"端口:1833,已启动MQTT服务器 !!");
            await Task.CompletedTask;
        }
        /// <summary>
        /// 停止服务
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task StopAsync(CancellationToken cancellationToken) {


            await Task.CompletedTask;
        }

        public void Dispose() {

        }
    }
}
